package Models;

import byggemarked.Console;
import java.util.ArrayList;

/**
 * @author Erik
 */
public class EmployeeCollection {

    private ArrayList<Employee> employees;
    private static EmployeeCollection instance = new EmployeeCollection();

    private EmployeeCollection()
    {
        this.employees = new ArrayList<Employee>();
		this.employees.add(new Employee("Finn Nørbygaard", Location.HardwareStore));
		this.employees.add(new Employee("Erik Barrett", Location.HardwareStore));
		this.employees.add(new Employee("Tanja Mariager", Location.LumberYard));
		this.employees.add(new Employee("Thomas Wøhlk Larsen", Location.LumberYard));
		this.employees.add(new Employee("Morten Spleth Heidemann Gregersen", Location.HardwareStore));
    }

    public static EmployeeCollection getInstance()
	{
		return EmployeeCollection.instance;
	}

    public boolean addEmployee(Employee newEmployee)
    {
        return this.employees.add(newEmployee);
    }

    public ArrayList<Employee> findEmployee(String name, Location location)
    {
        ArrayList<Employee> result = new ArrayList<Employee>();

        for (Employee employee : this.employees)
		{
			if(employee.isActivated())
			{
				boolean found = false;
				if (name != null && !name.equals(""))
				{
					if(employee.getName().toLowerCase().contains(name.toLowerCase()))
					{ found = true; }
				}
				else if(employee.getLocation().equals(location))
				{ found = true; }

				if (found)
				{
					result.add(employee);
				}
			}
        }
		return result;
    }

    public Employee getEmployee(int id)
    {
        for(Employee employee : this.employees){
            if(employee.getId() == id){
                return employee;
            }
        }
		return null;
    }

	public ArrayList<Employee> getAllEmployees()
	{
		ArrayList<Employee> activatedEmployee = new ArrayList<Employee>();
		for (Employee employee : this.employees)
		{
			if(employee.isActivated())
			{
				activatedEmployee.add(employee);
			}
		}
		return activatedEmployee;
	}

    public void removeEmployee(Employee employee)
    {
        employee.setActivated(false);
    }
}
